<?php
$isReloadable = true;
require_once("../../../pers/inc.config.php");
require_once('../../_inc/inc.session.php');
require_once('../../_inc/funct.html.php');

$sql_sel = "SELECT d.cod_dato, d.descr FROM rgl_mod_rbil mb " 
		." INNER JOIN rgl_def_dato d ON mb.id_set_dati = d.id_set_dati "
		."    AND d.tipo_tab_dati = mb.tipo_tab_indici "
		." WHERE mb.id_mod_rbil = ".reqVarInt('id')
		."   AND d.tipo_valore <> 'label'"
		." ORDER BY d.cod_dato "
		;
$objDB->query($sql_sel,'selRec');
$aCodDato = array(''=>'-- seleziona un indice');
while($acX = $objDB->fetch('selRec')) {
	$aCodDato[$acX['cod_dato']] = $acX['descr'];
}
$sql_sel = "SELECT d.cod_sett, d.descr FROM rgl_settore d " 
		." ORDER BY d.cod_sett "
		;
$objDB->query($sql_sel,'selRec');
$aCodSett = array(''=>'-- seleziona un settore','***'=>'*** - Settore generico');
while($acX = $objDB->fetch('selRec')) {
	if (reqVar('se')=='' or reqVar('se')==$acX['cod_sett'])
		$aCodSett[$acX['cod_sett']] = $acX['cod_sett']." - ".$acX['descr'];
}
$sql_sel = "SELECT p.*, d.descr AS d_descr "
		.", m.cod_mod_rbil, m.descr AS m_descr, s.descr AS s_descr " 
		." FROM rgl_mod_rbil m " 
		." LEFT JOIN rgl_mod_rbil_par_ind p ON p.id_mod_rbil = m.id_mod_rbil "
		."    AND p.cod_sett = '".reqVarAS('se')."'"
		." LEFT JOIN rgl_def_dato d ON d.cod_dato = p.cod_dato "
		."    AND d.id_set_dati = m.id_set_dati "
		." LEFT JOIN rgl_settore s ON s.cod_sett = p.cod_sett "
		." WHERE m.id_mod_rbil = ".reqVarInt('id')
		." ORDER BY p.cod_sett "
		;
$objDB->query($sql_sel,'selRec');
if (!$acX = $objDB->fetch('selRec')) {
	die ('parIndSettMod - no id. '.$sql_sel);
}
reqDef('cod_sett',reqVar('se'));
reqDef('cod_mod_rbil',$acX['cod_mod_rbil']);
reqDef('m_descr',$acX['m_descr']);
$nn=0;
if (!empty($acX['cod_sett'])) while($acX) {
	$nn++;
	reqDef('parind_cod_dato_'.$nn,$acX['cod_dato']);
	reqDef('parind_soglia25_'.$nn,num2str($acX['soglia25'],3));
	reqDef('parind_soglia50_'.$nn,num2str($acX['soglia50'],3));
	reqDef('parind_soglia75_'.$nn,num2str($acX['soglia75'],3));
	reqDef('parind_soglia100_'.$nn,num2str($acX['soglia100'],3));
	reqDef('parind_media_rif_'.$nn,num2str($acX['media_rif'],3));
	reqDef('parind_peso_'.$nn,num2str($acX['peso'],0));
	$acX = $objDB->fetch('selRec');
}
$cmdL = "";
	
$cmdR = "&nbsp;&nbsp;&nbsp;";
$cmdR .= "<a class=\"cmd1\" href=\"parIndSettMod.php?id=".reqVar('id')
	."&se=".reqVar('se')."&xsn=".XSN."\">modifica</a>";
$cmdR .= cmdTorna(); 

testaHtml('Gestione modelli',  $msgPag, 'modl');
echo getHtmlForm();
echo getHtmlHidden('xsn',XSN);
echo getHtmlHidden('id');
echo getHtmlHidden('se');
?>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">
         <?=$cmdL?>
      </td>
      <td class="cmd1" align="right">
         <?=$cmdR?>
      </td>
   </tr>
</table>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
	<?=getHtmlRigaRif();?>
   <tr>
      <td class="tit1" colspan='20' align='center'>Soglie settore</td>
   </tr>
   <tr>
      <td class="lab1" align="left" colspan='2'>Modello</td>
      <td class="txt1" align="left" colspan='2'>
         <?=getHtmlVisText('cod_mod_rbil')?>
      </td>
      <td class="txt1" align="left" colspan='16'>
         <?=getHtmlVisText('m_descr')?>
      </td>
   </tr>
   <tr>
      <td class="lab1" align='left' colspan='2'>Codice settore</td>
      <td class="txt1" align='left' colspan='18'>
<?
echo getHtmlVisDecode('cod_sett',$aCodSett);
?>
		</td>
   </tr>
   <tr>
      <td class="lab1" align='center' colspan='9' rowspan='2'>Indice</td>
      <td class="lab1" align='center' colspan='8'>Soglie</td>
      <td class="lab1" align='center' colspan='2' rowspan='2'>Media</td>
      <td class="lab1" align='center' colspan='1' rowspan='2'>Peso</td>
   </tr>
   <tr>
      <td class="lab1" align='center' colspan='2'>25</td>
      <td class="lab1" align='center' colspan='2'>50</td>
      <td class="lab1" align='center' colspan='2'>75</td>
      <td class="lab1" align='center' colspan='2'>100</td>
   </tr>
         <? 
$clRF = 'txt2';
foreach($_REQUEST as $nX => $vX) {
	if (substr($nX,0,16)!='parind_cod_dato_') continue;
	$nn = substr($nX,16);
	$clRF = ($clRF=='txt1')?'txt2':'txt1';	
?>
   <tr>
      <td class="<?=$clRF?>" colspan='2'>
            <?
            echo getHtmlVisText('parind_cod_dato_'.$nn);
            ?>
      </td>
      <td class="<?=$clRF?>" colspan='7'>
            <?
            echo getHtmlVisDecode('parind_cod_dato_'.$nn, $aCodDato);
            ?>
      </td>
      <td class="<?=$clRF?>" align='right' colspan='2'>
      	<? echo getHtmlVisText('parind_soglia25_'.$nn); ?>
      </td>
      <td class="<?=$clRF?>" align='right' colspan='2'>
      	<? echo getHtmlVisText('parind_soglia50_'.$nn); ?>
      </td>
      <td class="<?=$clRF?>" align='right' colspan='2'>
      	<? echo getHtmlVisText('parind_soglia75_'.$nn); ?>
      </td>
      <td class="<?=$clRF?>" align='right' colspan='2'>
      	<? echo getHtmlVisText('parind_soglia100_'.$nn); ?>
      </td>
      <td class="<?=$clRF?>" align='right' colspan='2'>
      	<? echo getHtmlVisText('parind_media_rif_'.$nn); ?>
      </td>
      <td class="<?=$clRF?>" align='right' colspan='1'>
      	<? echo getHtmlVisText('parind_peso_'.$nn); ?>
      </td>
   </tr>
<?    
}
?>
</table>
<table class="cmd1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left">
         <?=$cmdL?>
      </td>
      <td class="cmd1" align="right">
         <?=$cmdR?>
      </td>
   </tr>
</table>
<?
echo "</form>\n";
codaHtml();
exit();
